﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>


    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script language="javascript" type="text/javascript">
        //    排序按钮的点击事件
        // function sort(btnObj) {
        //     if (btnObj.className == "sort_desc") {
        //           btnObj.className = "sort_asc";
        //     }else{
        //         btnObj.className = "sort_desc";
        //         }

        //启用
        function startFee() {
            var r = window.confirm("确定要启用此资费吗？资费启用后将不能修改和删除。");
            document.getElementById("operate_result_info").style.display = "block";
        }

        //删除
        function deleteFee() {
            var r = window.confirm("确定要删除此资费吗？");
            document.getElementById("operate_result_info").style.display = "block";
        }
    </script>
    <script src="../js/module.js"></script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="#">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="../index.html" class="index_off"></a></li>
        <li><a href="../user/user_info.html" class="information_off"></a></li>
        <li><a href="../user/user_modi_pwd.html" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--排序-->
        <div class="search_add">
            <div>
                <!--<input type="button" value="月租" class="sort_asc" onclick="sort(this);" />-->
                <input type="button" value="基费" class="sort_asc" onclick="sort1(this);"/>
                <input type="button" value="时长" class="sort_asc" onclick="sort(this);"/>
            </div>
            <input type="button" value="增加" class="btn_add" onclick="location.href='fee_add.html';"/>
        </div>
        <!--启用操作的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th>资费ID</th>
                    <th class="width100">资费名称</th>
                    <th>基本时长</th>
                    <th>基本费用</th>
                    <th>单位费用</th>
                    <th>创建时间</th>
                    <th>开通时间</th>
                    <th class="width50">状态</th>
                    <th class="width200"></th>
                </tr>
                <tbody id="tbody"></tbody>
                <!--<tr>-->
                <!--<td>1</td>-->
                <!--<td><a href="fee_detail.html">包 20 小时</a></td>-->
                <!--<td>20 小时</td>-->
                <!--<td>24.50 元</td>-->
                <!--<td>3.00 元/小时</td>-->
                <!--<td>2013/01/01 00:00:00</td>-->
                <!--<td></td>-->
                <!--<td>暂停</td>-->
                <!--<td>-->
                <!--<input type="button" value="启用" class="btn_start" onclick="startFee();" />-->
                <!--<input type="button" value="修改" class="btn_modify" onclick="location.href='fee_modi.html';" />-->
                <!--<input type="button" value="删除" class="btn_delete" onclick="deleteFee();" />-->
                <!--</td>-->
                <!--</tr>-->
                <!--<tr>-->
                <!--<td>2</td>-->
                <!--<td><a href="fee_detail.html">包 40 小时</a></td>-->
                <!--<td>40 小时</td>-->
                <!--<td>40.50 元</td>-->
                <!--<td>3.00 元/小时</td>-->
                <!--<td>2013/01/21 00:00:00</td>-->
                <!--<td>2013/01/23 00:00:00</td>-->
                <!--<td>开通</td>-->
                <!--<td>                                -->
                <!--</td>-->
                <!--</tr>-->
            </table>
            <p>业务说明：<br/>
                1、创建资费时，状态为暂停，记载创建时间；<br/>
                2、暂停状态下，可修改，可删除；<br/>
                3、开通后，记载开通时间，且开通后不能修改、不能再停用、也不能删除；<br/>
                4、业务账号修改资费时，在下月底统一触发，修改其关联的资费ID（此触发动作由程序处理）
            </p>
        </div>
        <!--分页-->
        <div id="pages">
            <a href="#">上一页</a>
            <a href="#" class="current_page">1</a>
            <a href="#">2</a>
            <a href="#">3</a>
            <a href="#">4</a>
            <a href="#">5</a>
            <a href="#">下一页</a>
        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司</p>
</div>
</body>
<script type="text/javascript">
    $(function () {
        $.ajax({
            method: "GET",
            url: "../cost/findAll",
            dateType: "json",
            success: function (data) {
                console.log(data);
                var tbody = $('#tbody');
                for (var item of data) {
                    var tr = $('<tr></tr>');
                    var costId = $('<td></td>').text(item.costId);
                    var name = $('<td></td>').text(item.name);
                    var baseDuration = $('<td></td>').text(item.baseDuration);
                    var baseCost = $('<td></td>').text(item.baseCost);
                    var unitCost = $('<td></td>').text(item.unitCost);
                    var creatime = $('<td></td>').text(item.creatime);
                    var startime = $('<td></td>').text(item.startime);
                    var status = $('<td></td>').text(item.status);

                    var td = $('<td ></td>');
                    var btnStart = $('<input type="button"  value="启用" class="btn_start"   />');
                    //  var btnModify = $('<input type="button" value="修改" class="btn_modify" onclick="location.href=\'fee_modi.html?costId=\'+costId;" />');
                    var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                    var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');
                    if (item.status == 0) {
                        // $('#td1').hide()
                        td.append(btnStart).append(btnModify).append(btnDelete);
                    }
                    tr.append(costId).append(name).append(baseDuration).append(baseCost).append(unitCost)
                        .append(creatime).append(startime).append(status).append(td);
                    tbody.append(tr)
                }

            }
        });



        $('#datalist').click(function (e) {
            //获取目标里的第一个内容(parentNode父级\firstChild第一个儿子\textContent获取内容)
            var id = e.target.parentNode.parentNode.firstChild.textContent;
            console.log(e.target.value);
            console.log(id);
            //获取点击的内容
            var elem = e.target.value;

            if (elem === "启用") {
                $.ajax({
                    url: "/kobe/cost/upStatus",
                    type: "POST",
                    data: {
                        "num": id
                    },
                    //刷新页面
                    success: function (resp) {
                        location.reload(true)
                    }
                })
            }
            if (elem === "删除") {
                $.ajax({
                    url: "/kobe/cost/delOne",
                    type: "POST",
                    data: {
                        "costId": id
                    },
                    success: function (resp) {
                        location.reload(true)
                    }
                })
            }
            if (elem === "修改") {
                $.ajax({
                    url: "fee_modi.html",
                    data: {
                        id: id
                    },
                    success: function () {
                        location.href = "fee_modi.html?costId=" + id
                    }
                })
            }
        });
    });

    //    排序按钮的点击事件
    function sort(btnObj) {
        if (btnObj.className == "sort_desc") {
            btnObj.className = "sort_asc";
            $('#tbody').empty();
            $.ajax({
                url: "/kobe/cost/bdAsc;",
                type: "POST",
                dateType: "json",
                success: function (data) {
                    console.log(data);
                    var tbody = $('#tbody');
                    for (var item of data) {
                        var tr = $('<tr></tr>');
                        var costId = $('<td></td>').text(item.costId);
                        var name = $('<td></td>').text(item.name);
                        var baseDuration = $('<td></td>').text(item.baseDuration);
                        var baseCost = $('<td></td>').text(item.baseCost);
                        var unitCost = $('<td></td>').text(item.unitCost);
                        var creatime = $('<td></td>').text(item.creatime);
                        var startime = $('<td></td>').text(item.startime);
                        var status = $('<td></td>').text(item.status);

                        var td = $('<td id="td1"></td>');
                        var btnStart = $('<input type="button"  value="启用" class="btn_start"   />');
                        //  var btnModify = $('<input type="button" value="修改" class="btn_modify" onclick="location.href=\'fee_modi.html?costId=\'+costId;" />');
                        var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                        var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');
                        if (item.status == 0) {
                            // $('#td1').hide()
                            td.append(btnStart).append(btnModify).append(btnDelete);
                        }
                        tr.append(costId).append(name).append(baseDuration).append(baseCost).append(unitCost)
                            .append(creatime).append(startime).append(status).append(td);
                        tbody.append(tr)
                    }
                }

            })
        } else {
            btnObj.className = "sort_desc";
            $('#tbody').empty();
            $.ajax({
                url: "/kobe/cost/bdDesc;",
                type: "POST",
                dateType: "json",
                success: function (data) {
                    console.log(data);
                    var tbody = $('#tbody');
                    for (var item of data) {
                        var tr = $('<tr></tr>');
                        var costId = $('<td></td>').text(item.costId);
                        var name = $('<td></td>').text(item.name);
                        var baseDuration = $('<td></td>').text(item.baseDuration);
                        var baseCost = $('<td></td>').text(item.baseCost);
                        var unitCost = $('<td></td>').text(item.unitCost);
                        var creatime = $('<td></td>').text(item.creatime);
                        var startime = $('<td></td>').text(item.startime);
                        var status = $('<td></td>').text(item.status);

                        var td = $('<td id="td1"></td>');
                        var btnStart = $('<input type="button"  value="启用" class="btn_start"   />');
                        //  var btnModify = $('<input type="button" value="修改" class="btn_modify" onclick="location.href=\'fee_modi.html?costId=\'+costId;" />');
                        var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                        var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');
                        if (item.status == 0) {
                            // $('#td1').hide()
                            td.append(btnStart).append(btnModify).append(btnDelete);
                        }
                        tr.append(costId).append(name).append(baseDuration).append(baseCost).append(unitCost)
                            .append(creatime).append(startime).append(status).append(td);
                        tbody.append(tr)
                    }
                }
            })
        }
    }

    function sort1(btnObj) {
        if (btnObj.className == "sort_desc") {
            btnObj.className = "sort_asc";
            $('#tbody').empty();
            $.ajax({
                url: "/kobe/cost/bcAsc;",
                type: "POST",
                dateType: "json",
                success: function (data) {
                    console.log(data);
                    var tbody = $('#tbody');
                    for (var item of data) {
                        var tr = $('<tr></tr>');
                        var costId = $('<td></td>').text(item.costId);
                        var name = $('<td></td>').text(item.name);
                        var baseDuration = $('<td></td>').text(item.baseDuration);
                        var baseCost = $('<td></td>').text(item.baseCost);
                        var unitCost = $('<td></td>').text(item.unitCost);
                        var creatime = $('<td></td>').text(item.creatime);
                        var startime = $('<td></td>').text(item.startime);
                        var status = $('<td></td>').text(item.status);

                        var td = $('<td id="td1"></td>');
                        var btnStart = $('<input type="button"  value="启用" class="btn_start"   />');
                        //  var btnModify = $('<input type="button" value="修改" class="btn_modify" onclick="location.href=\'fee_modi.html?costId=\'+costId;" />');
                        var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                        var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');
                        if (item.status == 0) {
                            // $('#td1').hide()
                            td.append(btnStart).append(btnModify).append(btnDelete);
                        }
                        tr.append(costId).append(name).append(baseDuration).append(baseCost).append(unitCost)
                            .append(creatime).append(startime).append(status).append(td);
                        tbody.append(tr)
                    }
                }
            })
        } else {
            btnObj.className = "sort_desc";
            $('#tbody').empty();
            $.ajax({
                url: "/kobe/cost/bcDesc;",
                type: "POST",
                dateType: "json",
                success: function (data) {
                    console.log(data);
                    var tbody = $('#tbody');
                    for (var item of data) {
                        var tr = $('<tr></tr>');
                        var costId = $('<td></td>').text(item.costId);
                        var name = $('<td></td>').text(item.name);
                        var baseDuration = $('<td></td>').text(item.baseDuration);
                        var baseCost = $('<td></td>').text(item.baseCost);
                        var unitCost = $('<td></td>').text(item.unitCost);
                        var creatime = $('<td></td>').text(item.creatime);
                        var startime = $('<td></td>').text(item.startime);
                        var status = $('<td></td>').text(item.status);

                        var td = $('<td id="td1"></td>');
                        var btnStart = $('<input type="button"  value="启用" class="btn_start"   />');
                        //  var btnModify = $('<input type="button" value="修改" class="btn_modify" onclick="location.href=\'fee_modi.html?costId=\'+costId;" />');
                        var btnModify = $('<input type="button" value="修改" class="btn_modify"  />');
                        var btnDelete = $('<input  type="button"  value="删除" class="btn_delete"  />');
                        if (item.status == 0) {
                            // $('#td1').hide()
                            td.append(btnStart).append(btnModify).append(btnDelete);
                        }
                        tr.append(costId).append(name).append(baseDuration).append(baseCost).append(unitCost)
                            .append(creatime).append(startime).append(status).append(td);
                        tbody.append(tr)
                    }
                }
            })
        }
    }
</script>

</html>
